
void main(){

  //变量
  var ll = "11";

  // 常量：const
  const a = 1;
  const b = a * 10;
  print(b);

  //常量：final
  final c = const[a];
  print(c);

//  基本数据类型：Number -> int /  double
  int num_1 = 1;
  double num_2 = 3.14;

//  基本数据类型：Boolen
  var bool_1 = true;

//  基本数据类型：String
  var s1 = "Hi";
  var s2 = "Flutter";
  print(s1 + s2);

  var s3 = """哈哈哈，
  我就是我，
  是不一样的烟火！
  """;
  print(s3);

//  基本数据类型：List
  var list_1 = [1,2,3,4,5];
  print(list_1);

//  基本数据类型：Map
  var map_1 = {
    "one":"1",
    "two":"2",
    "fhree":"3",
    "four":"4",
    "five":"5",
  };

  print(map_1);

  var map_2 = new Map();
  map_2["one"] = "1";
  map_2["two"] = "2";
  map_2["three"] = "3";
  map_2["four"] = "4";
  map_2["five"] = "5";

  print(map_2);

  if(map_2["0"] == null){
    print("Map中不存在这样的key");
  }


//  函数
  print(equal("0", "1"));

  print(getUserInfo("追梦小乐", "男"));
  print(getUserInfo("追梦小乐", "男","百度百科"));

//  算术运算符
  print(1 + 2);
  print(2 -1);
  print(2 * 5);
  print(5 / 3);
  print(5 ~/ 2);
  print(5 % 2);

  var i_a,i_b;
  i_a = 0;
  i_b = ++i_a;
  print(i_a == i_b);

  i_a = 0;
  i_b = i_a++;
  print(i_a == i_b);

//  关系运算符: ==  !=  >  <  >=  <=

//  类型操作符：as  is  is!

//  赋值操作符：=  +=  -=  ??= (变量为null的时候才赋值)
  var aa,bb;
  var value = 2;
  aa = value;
  bb ??= value;
  print(bb);

//  逻辑运算符：&&  || !&&  !||

//  级联操作（语法的一部分）： ..

  // for 语句
  var message = new StringBuffer("Hello Dart!");
  for(var i = 0; i < 5;i++){
    message.write("!");
  }
  print(message);

  var arr = [0,1,2,3,4,5];
  for(var i in arr){
    print(i);
  }

//  assert : 为 false 时抛出异常，后面的语句不执行
  var text = "11";
//  assert(text == null);
  print(text);


  try {
   var div_1 = 1 / 0;
   print(div_1);
  }on Exception catch(e){
    print("Exception Detail: \n $e");
  }catch(e,s){
    print("Exception Detail: \n $e");
    print("stack trace: \n $s");
  }

  //实例化成员变量
  var user = new User("A",1);
  user.name = "追梦小乐";
  user.age = 20;

  //读取和写入数据
  var rectangle = new Rectangle(3, 4, 20, 15);

  List<Color> values = Color.values;
  print(values);

  T t = new T();
  t.a();
  t.b();

}

bool equal(String s1,String s2){
  return s1 == s2;
}

//可变参数
String getUserInfo(String name,String sex,[String from]){
  var info = "$name 的性别是 $sex";
  if(from != null){
    info = "$info 信息来自 $from";
  }
  return info;
}

//默认参数
String getUserInfo_1(String name,String sex,[String from = "中国"]){
  var info = "$name 的性别是 $sex";
  if(from != null){
    info = "$info 信息来自 $from";
  }
  return info;
}

class User{
  String name;
  int age;


  //常规构造函数
  User(this.name,this.age);

  //命名构造函数
  User.fromJson(Map json){
    name = json["name"];
    age = json["age"];
  }
}

class Rectangle{
  num left;
  num top;
  num width;
  num height;

  Rectangle(this.left,this.top,this.width,this.height);

  num get right => left + width;

  set right(num value) => left = value - width;

  num get bottom => top + height;

  set bottom(num value) => top = value = height;
}

//重载函数
class Vector{
  final int x;
  final int y;

  const Vector(this.x,this.y);

  Vector operator +(Vector v){
    return new Vector(x + v.x, y + v.y);
  }

  Vector operator -(Vector v){
    return new Vector(x - v.x, y - v.y);
  }
}


//继承
class Animals{

  void eat(){
    print("动物会吃");
  }

  void run(){
    print("动物会跑");
  }
}

class People extends Animals{

  void study(){
    print("人类会学习");
  }
}


//抽象
abstract class BaseDataBase{

  void add();

  void delete();

  void update();

  void query();
}

class MyDataBase extends BaseDataBase{
  @override
  void add() {
    // TODO: implement add
  }

  @override
  void delete() {
    // TODO: implement delete
  }

  @override
  void query() {
    // TODO: implement query
  }

  @override
  void update() {
    // TODO: implement update
  }

}

//枚举
enum Color {
  red,

  green,

  blue
}

class S{
  a(){
    print("S.a");
  }
}

class A{
  a(){
    print("A.a");
  }

  b(){
    print("A.b");
  }
}

class T = A with S;